package OneHomeWork;

import jdk.nashorn.internal.ir.IfNode;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ShowOffText {

    public static void main(String[] args) {


        File file=new File("D:\\Idea\\DOME\\j180_class_code\\javaoo_21\\作业.txt");

        if (!file.exists()){

            try {

                file.createNewFile();

            } catch (IOException e) {

                e.printStackTrace();
            }
        }if (file.isDirectory()){

            file.delete();
        }

        String workPath= System.getProperty("user.dir");

//        System.out.println(file);

        File file1=new File(workPath+File.separator+"11-19"+File.separator+"files.txt");

        if (!file1.exists()){
//        System.out.println(file1);{
            try {

                file1.createNewFile();

            } catch (IOException e) {

                e.printStackTrace();
            }
        }

        try {

            Reader reader=new FileReader(file);

            Writer writer=new FileWriter(file1);

            char[] buf=new char[5000];

            int length=0;

            while ((length=reader.read(buf,0,buf.length))!=-1){

                writer.write(buf,0,buf.length);
            }

            writer.flush();

        } catch (IOException e) {

            e.printStackTrace();

        }
        List<StudentBean> studentsInfo=new ArrayList();

        studentsInfo.add(new StudentBean(1,"李菊花","男",19));
        studentsInfo.add(new StudentBean(2,"王菊花","女",20));
        studentsInfo.add(new StudentBean(3,"张菊花","男",22));
        studentsInfo.add(new StudentBean(4,"刘菊花","女",24));
        studentsInfo.add(new StudentBean(5,"赵菊花","男",26));
        studentsInfo.add(new StudentBean(6,"周菊花","男",20));


        File file2=new File("D:\\Idea\\j180git\\11-19\\abcd.txt");

        if(!file2.exists()){

            try {

                file2.createNewFile();

            } catch (IOException e) {

                e.printStackTrace();
            }

        }

        String student="编号     姓名   性别  年龄"+"\n";

        Writer writer;

        try {
            writer=new FileWriter(file2,true);

            for (StudentBean studentBean : studentsInfo) {

                student+=studentBean.getStudentId()+"\t"+studentBean.getName()+"\t"+studentBean.getGender()+"\t"+studentBean.getAge()+"\n";
            }

            writer.write(student);

            writer.flush();

        } catch (IOException e) {

            e.printStackTrace();
        }

//        System.out.println(student);

        System.out.println(file2);

    }



}
